/*****通用函数*********/

/**
 * 获取URL参数
 * @param name:url字段名称
 */
function GetUrlArg(name){
	var url=location.href;if(url.substring(url.length-1)=="#"){url=url.substring(0,url.length-1);};var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");       if (reg.test(url)) return unescape(RegExp.$2.replace(/\+/g, " ")); return ""; };

//关闭AJAX缓存 
$.ajaxSetup ({ 
    cache: false 
});


/****************************消息提示Start*****************************/
//普通消息提示
function showMsg(msg){
	layer.msg(msg);
}
//弹层Iframe
function openLayer(url){
	layer.open({
		type: 2,
		area: ['700px', '530px'],
		fix: false, //不固定
		maxmin: true,
		content: url
	});
}
//简洁弹窗
function msgOpen(url,width,heigth){
	window.top.layer.open({
	  type: 2,
	  title: false,
	  shadeClose: true,
	  shade: 0.3,
	  area: [width, heigth],
	  content: url //iframe的url
	});
}

/**
 * 弹层iFrame,自定义宽高度
 * @param url
 * @param width
 * @param height
 * @return
 */
function openLayer(url,width,height){
	layer.open({
		type: 2,
		area: [width+'px', height+'px'],
		fix: false, //不固定
		maxmin: true,
		content: url
	});
}

/**
 * 弹层Iframe,自定义宽高度(带标题)
 * @param title
 * @param url
 * @param width
 * @param height
 * @return
 */
function openTitleLayer(title,url,width,height){
	layer.open({
		title: title,
		type: 2,
		area: [width+'px', height+'px'],
		fix: false, //不固定
		maxmin: true,
		content: url,
		
	});
}
function openTitleLayer2(title,url,width,height){
	layer.open({
		title: title,
		type: 2,
		area: [width+'px', height+'px'],
		fix: false, //不固定
		maxmin: true,
		content: url,
		cancel:function(){
			//if(window.opener){
				$("#searchTable").datagrid('reload');
			//}
		}
	});
}
function openTitleLayers(title,url,width,height){
	layer.open({
		title: title,
		type: 2,
		area: [width+'%', height+'%'],
		fix: false, //不固定
		maxmin: true,
		content: url
	});
}


//关闭层iframe
function closeLayer(){
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	parent.layer.close(index);
}

/**
 * 关闭层iframe,并提示消息
 * @param msg: 提示消息
 * @return
 */
function closeLayerAndMsg(msg){
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	parent.layer.msg(msg);
	parent.layer.close(index);
}

/****************************消息提示End*****************************/

/****************************Grid通用方法Start*****************************/
//删除
function delModel(id,title,url,retrunUrl){
	layer.confirm("您确定要删除 "+title+" 吗", {icon: 3}, function(index){
	    $.post(url,{id:id},function(data){
	    	var iconType = 6;
	    	if(data.success==false){
	    		iconType = 5;
	    	}
	    	layer.alert(data.msg, {icon: iconType},function(){
	    		location.href=retrunUrl;
	    	});
  	    });
	});
}
/**阿拉伯转中文**/

function convertCurrency(currencyDigits) {
	// Constants:
	var MAXIMUM_NUMBER = 99999999999.99;
	// Predefine the radix characters and currency symbols for output:
	var CN_ZERO = "零";
	var CN_ONE = "壹";
	var CN_TWO = "贰";
	var CN_THREE = "叁";
	var CN_FOUR = "肆";
	var CN_FIVE = "伍";
	var CN_SIX = "陆";
	var CN_SEVEN = "柒";
	var CN_EIGHT = "捌";
	var CN_NINE = "玖";
	var CN_TEN = "拾";
	var CN_HUNDRED = "佰";
	var CN_THOUSAND = "仟";
	var CN_TEN_THOUSAND = "万";
	var CN_HUNDRED_MILLION = "亿";
	var CN_SYMBOL = "人民币";
	var CN_DOLLAR = "元";
	var CN_TEN_CENT = "角";
	var CN_CENT = "分";
	var CN_INTEGER = "整";

	// Variables:
	var integral; // Represent integral part of digit number.
	var decimal; // Represent decimal part of digit number.
	var outputCharacters; // The output result.
	var parts;
	var digits, radices, bigRadices, decimals;
	var zeroCount;
	var i, p, d;
	var quotient, modulus;
	
	if(currencyDigits!=null){
	
	// Validate input string:
	currencyDigits = currencyDigits.toString();
	//如果是负值，大写金额前面拼接负号，且把负号去除再转换
	if(currencyDigits.charAt(0) == "-"){
		currencyDigits=currencyDigits.substr(1);
		outputCharacters = "负";	
	}else{
		outputCharacters="";
	}
	if (currencyDigits == "") {
	alert("Empty input!");
	return "";
	}
	
	if (currencyDigits.match(/[^,.\d]/) != null) {
	alert("Invalid characters in the input string!");
	return "";
	}
	if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
	alert("Illegal format of digit number!");
	return "";
	}

	// Normalize the format of input digits:
	currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
	currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
	// Assert the number is not greater than the maximum number.
	if (Number(currencyDigits) > MAXIMUM_NUMBER) {
	alert("Too large a number to convert!");
	return "";
	}

	// Process the coversion from currency digits to characters:
	// Separate integral and decimal parts before processing coversion:
	parts = currencyDigits.split(".");
	if (parts.length > 1) {
	integral = parts[0];
	decimal = parts[1];
	// Cut down redundant decimal digits that are after the second.
	decimal = decimal.substr(0, 2);
	}
	else {
	integral = parts[0];
	decimal = "";
	}
	// Prepare the characters corresponding to the digits:
	digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
	radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
	bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
	decimals = new Array(CN_TEN_CENT, CN_CENT);
	// Start processing:
	//outputCharacters = "";
	// Process integral part if it is larger than 0:
	if (Number(integral) > 0) {
	zeroCount = 0;
	for (i = 0; i < integral.length; i++) {
	p = integral.length - i - 1;
	d = integral.substr(i, 1);
	quotient = p / 4;
	modulus = p % 4;
	if (d == "0") {
	zeroCount++;
	}
	else {
	if (zeroCount > 0)
	{
	outputCharacters += digits[0];
	}
	zeroCount = 0;
	outputCharacters += digits[Number(d)] + radices[modulus];
	}
	if (modulus == 0 && zeroCount < 4) {
	outputCharacters += bigRadices[quotient];
	}
	}
	outputCharacters += CN_DOLLAR;
	}
	// Process decimal part if there is:
	if (decimal != "") {
	for (i = 0; i < decimal.length; i++) {
	d = decimal.substr(i, 1);
	if (d != "0") {
	outputCharacters += digits[Number(d)] + decimals[i];
	}
	}
	}
	// Confirm and return the final output string:
	if (outputCharacters == "") {
	outputCharacters = CN_ZERO + CN_DOLLAR;
	}
	if (decimal == "") {
	outputCharacters += CN_INTEGER;
	}
	}
	//outputCharacters = CN_SYMBOL + outputCharacters;
	return outputCharacters;
	}

/****************************Grid通用方法End*****************************/
//获取当前用户所有角色ID(2015.02.05)
function getUserRoleids(){
	/*
    var url="r?wf_num=R_Vivoray_B001";
    var roleids = "";
    jQuery.ajax({
        type:"post",
        async:false,
        url:url,
        success:function(data) {
            roleids = data;
        }
    });
    return roleids;
    */
}


/****************************选择公司/项目 Start*****************************/
$(function(){

  $.fn.hhDrop = function(options){
    var options = jQuery.extend({
        preLoadSrc:"images/loading.gif"
    }, options || {}); 


    var defaults = {};

    return this.each(function(){

      //默认
      var options = $.extend(defaults,options);
      var $this = $(this);

      var $boxSearch = $this.find('.boxSearch');
      var $lineSearchbg = $this.nextAll().find('.lineSearchbg');

      $boxSearch.click(function(){
        var _this = $(this);
        //点击本身显示隐藏
        if(_this.hasClass('boxSearchHover') ){
          _this.removeClass('boxSearchHover');
          _this.children('.btn_search').removeClass('btn_search_current');
          _this.parent().find('.search_form_suggest').hide();

        }else{
          _this.addClass('boxSearchHover');
          _this.children('.btn_search').addClass('btn_search_current');
          _this.parent().find('.search_form_suggest').show();
        }

        _this.next().find('.clr_after a').click(function(){
          
          _this.find('span.key_word b').text($(this).text());

        });


        _this.next().find('.search_city_result a').click(function(){
          
          _this.find('span.key_word b').text($(this).text());

        });

        //阻止冒泡
        $(document).bind('click',function(event){
          if(!$(event.target).parent().hasClass('boxSearch' )  && !$(event.target).hasClass('boxSearch') && !$(event.target).parent().parent().hasClass('boxSearch') && !$(event.target).hasClass('input_city') ){
            _this.children('.btn_search').removeClass('btn_search_current');
            _this.removeClass('boxSearchHover');
            _this.parent().find('.search_form_suggest').hide();
          }
        });
        
      });
      
      $lineSearchbg.each(function(){
        //搜索框 请输入目的地、主题或关键词
        $(this).find('#arriveSearchText').focus(function(){
          var arrive = $(this).val();
          if(arrive == '请输入目的地、主题或关键词'){
            $(this).val('').css('color','#000');
          }
        });
        $(this).find('#arriveSearchText').blur(function(){
          var arrive = $(this).val();
          if(arrive == ''){
            $(this).val('请输入目的地、主题或关键词').css('color','#b5b5b5');
          }
        });

        //删除搜索信息
        $(this).find('#btn_delete').click(function(){
          $(this).prev('#arriveSearchText').focus().val('').css('color','#000');
        });

      });
  });
    
} 

});

//选择客户 
function selCustomer(isOperational ){
	var url="uc_customer/customerInfo/intention/intentionSel?isOperational="+isOperational;
	openLayer(url,1200,600);
}
//初始化父窗体选择客户的字段
function initSelCustomer(cusList){
	var cusArr;
	var html="<ul>";
	var html_li="";
	if(cusList.indexOf(",")>-1){
		cusArr=cusList.split(",");
		for(var i=0;i<cusArr.length;i++){
			html_li=html_li+"<li><input type='checkbox' name='cus"+i+"' value='"+cusArr[i]+"' />"+cusArr[i]+"</li>";
		}
	}else{
			html_li=html_li+"<li><input type='checkbox' name='cus1' value='"+cusList+"' />"+cusList+"</li>";
	}
	html=html+html_li+"</ul>";
	window.parent.$("#keList").html(html);
}
//选择合同模版
function chooseModel(){
	var hostName=$("base").attr("href");
	var type=$("#type").val();
	var id="";
	if(type=="contractAtt"){
		id="3760b8eca9f39d448e66e77addfc7d";
	}else if(type=="customerAtt"){
		id="1458b8eca9f39d448e66e77acetc78";
	}else if(type=="zhongzhixieyiAtt"){
		id="1458b8eca9f39d448e66e77addfc7d";
	}else if(type=="intentAtt"){
		id="2466be12c51cef1a048f0cf93c90a615";
	}else if(type=="buchongxieyiAtt"){
		id="a85eeaf0aafc57259ba2fa078cdc433e";
	}
	var url=hostName+"uc_document/documentTemplate/sel/"+id;
	OpenUrl(url,800,520);
}
//初始化父窗体选择模版字段
function initSelModel(id,fileType,filePath){
	window.opener.$("#fileId").val(id);
	window.opener.$("#fileType").val(fileType);
	window.opener.$("#filePath").val(filePath);
	window.opener.initDoc();
}
//编辑合同模版
function editContract(){
	var docUnid=$("#id").val();
	var type=$("#type").val();
	var hostName=$("base").attr("href");
	var url=hostName+"uc_document/documentTemplate/openDoc/"+docUnid+"_"+type;
	window.open(url);
}
//上传文本
function uploadText(){
	var docUnid=$("#id").val();
	var type=$("#type").val();
	var hostName=$("base").attr("href");
	var url=hostName+"uc_document/documentTemplate/toUploadText/"+docUnid+"_"+type;
	openTitleLayer("上传文本",url,550,300);
	
}
//上传协议
function uploadAgreement(){
	var docUnid=$("#id").val();
	var type = "buchongxieyiAtt";
	var hostName=$("base").attr("href");
	var url=hostName+"uc_document/documentTemplate/toUploadText/"+docUnid+"_"+type;
	openTitleLayer("上传协议",url,550,300);
}

//删除附件
function delAtt(id){
	layer.confirm("您确定删除吗？", {icon: 3}, function(index){
		var hostName=$("base").attr("href");
		var url = hostName + "file/del";
		jQuery.ajax({
	        type:"post",
	        async:false,
	        url:url,
	        dataType:"json",
	        data:{attId:id},
	        success:function(data){
	        	layer.alert(data.msg, {icon: 6},function(){
		    		location.href=location.href;
		    	});
	        }
		});
	});
        
}

//初始化正文列表
function initText(){
	var docUnid=$("#id").val();
	var type=$("#type").val();
	var hostName=$("base").attr("href");
	var url=hostName+"uc_document/documentTemplate/getText";
	jQuery.ajax({
        type:"post",
        async:false,
        url:url,
        dataType:"json",
        data:{docUnid:docUnid,type:type},
        success:function(data){
        	if( data!=null && data!=""){
        		//增加下载按钮
        		var btn_downLoad = "<span style='margin-left:30px;'>(<a style='color:#757575' href='uc_document/documentTemplate/showDoc/"+docUnid+"_"+type+"' target='_blank'>在线查看</a> &nbsp; <a style='cursor:pointer;color:#757575' onClick=downLoadText('"+data.id+"') >下载</a>)</span>";
        		if(data.fileName==""){
        			var html="<a style='cursor:pointer' onClick=downLoadText('"+data.id+"')>"+getTextByAttType(data.typeName)+"."+data.fileType+"</a>"+btn_downLoad;
        		}else{
        			var html="<a style='cursor:pointer' onClick=downLoadText('"+data.id+"')>"+data.fileName+"</a>"+btn_downLoad;
        		}
        		$("#textList").html(html);
        	}
        }
	});
	
	//加载协议文本
	if(document.getElementById("agreementList")!=null){
		type = "buchongxieyiAtt";
		jQuery.ajax({
	        type:"post",
	        async:false,
	        url:url,
	        dataType:"json",
	        data:{docUnid:docUnid,type:type},
	        success:function(data){
	        	if(data!=null && data!=""){
	        		//增加下载按钮
	        		var btn_downLoad = "<span style='margin-left:30px;'>(<a style='color:#757575' href='uc_document/documentTemplate/showDoc/"+docUnid+"_"+type+"' target='_blank'>在线查看</a> &nbsp; <a style='cursor:pointer;color:#757575' onClick=downLoadText('"+data.id+"') >下载</a>)</span>";
	        		if(data.fileName==""){
	        			var html="<a style='cursor:pointer' onClick=downLoadText('"+data.id+"')>"+getTextByAttType(data.typeName)+"."+data.fileType+"</a>"+btn_downLoad;
	        		}else{        			
	        			var html="<a style='cursor:pointer' onClick=downLoadText('"+data.id+"')>"+data.fileName+"</a>"+btn_downLoad;
	        		}
	        		$("#agreementList").html(html);
	        	}
	        }
		});
	}
}
function getTextByAttType(type){
	var name="";
	if(type=="contractAtt"){
		name="合同文本";
	}else if(type=="customerAtt"){
		name="客户代理文本";
	}else if(type=="formalAtt"){
		name="客户代理文本";
	}else if(type=="intentAtt"){
		name="意向书文本";
	}else if(type=="buchongxieyiAtt"){
		name="补充协议文本";
	}else if(type=="zhongzhixieyiAtt"){
		name="终止协议文本";
	}else{
		name="文档";
	}
	return name;
	
}
//下载正文文件
function downLoadText(id){
	var hostName=$("base").attr("href");
	var url=hostName+"uc_document/documentTemplate/download/"+id;
	window.open(url);
}
function downModel(){
	var hostName=$("base").attr("href");
	var url=hostName+"uc_document/documentTemplate/showDownloadModelList";
	openTitleLayer("下载模版",url,800,400);
}
/*自动完成*/
function autoComplete(v,url){
			  $("#auto1").AutoComplete({
				'data': url,//ajax url地址
				'ajaxDataType': 'json',//返回数据的格式
				'ajaxParams':v,//传递请求参数
				'onerror': function(msg){alert(msg);},//出错处理方法
				'maxItems':10,//最大待选条数
				'matchHandler': function(keyword, data){
           			 return data.label.indexOf(keyword) == 0;  // 匹配规则: 以输入框中的值开头且大小写敏感
       			},
				'beforeLoadDataHandler' : function(keyword){
          			  return keyword.length > 1;//关键字长度大于1时才发起请求
       			},
				//选择下拉时触发
				'afterSelectedHandler': function(data){
            		var html="<b class='size_14'>"+data.label+"</b> ";
					$("#key_word").html(html);
					$("#key_word_value").val($("#auto1").val());
					$("#auto1").val("");
					//$("#key_word_value").val(data.value);
					$(".search_form_suggest").hide();
        		}
			});
}

/* 根据承租日期，自动生成多段的承租日期和租金 */
/*
 * sid :开始日期的标签id，结束日期的标签id
 * 1.当日期失去焦点时，获取开始日期和结束日期，当两个日期都不为空的时候，在执行自动生成的函数
 * 2.
*/
function autoCreateMulti(sid,eid){
	var sdate;//开始字符串,选择的
	var edate;//结束字符串,选择的
	sdate=$("#"+sid).val();
	edate=$("#"+eid).val();
	//开始日期和结束日期都不为空
	if(sdate=="" || edate==""){
		return false;
	}
	//计算两个日期相差的年份
	var s_date=StringToDate(sdate);//开始日期
	var s_year=s_date.DatePart("y");//开始年
	var e_date=StringToDate(edate);//结束日期
	var e_year=e_date.DatePart("y");//结束年
	var diff=s_date.DateDiff("y",edate);
	//if(diff>0){diff--;}
	//var yJson=[{"sdate":"2014-01-01","edate":"2014-12-31"},{"sdate":"2015-01-01","edate":"2015-12-31"}];
	var yStr="[";//最终结果json字符串
	var temp="";//每个时间分段对象
	//如果没有跨年，则直接返回当前的开始和结束日期
	if(diff==0){
		temp="{\"sdate\":\""+sdate+"\",\"edate\":\""+edate+"\"}";
	}else{
		for(var i=0;i<=diff;i++){
			var sdate = s_date.DateAdd("y",i);
			var enddate = s_date.DateAdd("y",i+1).DateAdd("d",-1);
			if(i==diff){
				if(sdate<=e_date){
					temp=temp+",{\"sdate\":\""+sdate.Format("yyyy-MM-dd")+"\",\"edate\":\""+edate+"\"}";
				}
			}else{
				if(enddate>e_date){
					enddate = e_date;
				}
				temp=temp+",{\"sdate\":\""+sdate.Format("yyyy-MM-dd")+"\",\"edate\":\""+enddate.Format("yyyy-MM-dd")+"\"}";
			}
		}
		temp=temp.substring(1,temp.length);
	}
	yStr=yStr+temp+"]";
	var	yJson=eval('(' + yStr + ')');//获取结果，并转换为json数组
	//循环遍历json数组，并创建html标签
	var html="<table id='djList' class='table table-condensed'><thead><tr><th>年数</th><th>开始时间</th><th>结束时间</th><th>租金单价</th><th>月租金</th><th>金额大写</th></tr></thead><tbody>";
	var trHtml="";
	for(var i=0;i<yJson.length;i++){
		trHtml=trHtml+"<tr id='zjdj"+i+"'><td>第"+(i+1)+"年<input type='hidden' name='rentId"+i+"' id='rentId"+i+"' value='' /></td><td><input type='text' name='sdate"+i+"' class='Wdate' id='sdate"+i+"' value='"+yJson[i].sdate+"' onClick='WdatePicker()'/></td> <td><input type='text' name='edate"+i+"' class='Wdate' id='edate"+i+"' value='"+yJson[i].edate+"' onClick='WdatePicker()'/></td><td><input type='text' name='zujin"+i+"' id='zujin"+i+"' onkeyup='zidong("+i+")' />元/㎡/天</td><td><input type='text' name='yzj"+i+"' id='yzj"+i+"' onkeyup='capitalMonthlyRent("+i+",this.value)' />元</td><td><input type='text' name='jedx"+i+"' id='jedx"+i+"' /> &nbsp; <input type='button' value='删除' onclick=removeZJDJ("+i+") ></td></tr>"
	}
	html=html+trHtml+"</tbody></table>";
	$("#dynZJ").html(html);
}
//删除租金单价
function removeZJDJ(index){
	$("#zjdj"+index).remove();
}

//月租金变动时，大写跟随变动
function capitalMonthlyRent(i,val){
	if(val.indexOf(".")!=(val.length-1)){
		$("#jedx"+i).val(convertCurrency(val));
	}
}

function zidong(i){
	var unitArea=$("#unitArea").val();
	if(unitArea=="" ||  !checkNumber(unitArea)){
//		layer.alert("承租面积不合法...",{icon:7},function(i){
//			layer.close(i);
//			$("#unitArea").focus();
//		});
		$("#unitArea").focus();
		return false;
	}
	var zujin=$("#zujin"+i).val();
	if(!checkNumber(zujin)){
//		layer.alert("租金单价不合法...",{icon:7},function(i){
//			layer.close(i);
//			$("#zujin"+i).focus();
//		});
		$("#zujin"+i).focus();
		return false;
	}
	var yue=(zujin*unitArea*365)/12;
	$("#yzj"+i).val(yue.toFixed(2));
	$("#jedx"+i).val(convertCurrency(yue));
	
}
//修改面积时触发的函数
function changeArea(){
	var length=$("#djList").find("tr").length;
	for(var i=0;i<=length;i++){
		zidong(i);
	}
	
}
/******************************添加免租期*******************************************/
function addMzq(){
	var length=$("#dynMzq").find("tr").length;
	var index=length-1;
	var trStr="<tr><td><input type='hidden' name='id"+index+"' id='id"+index+"' value='' />  <input type='text' name='mzq_s"+index+"' onblur=calTotal('mzq_s"+index+"','mzq_e"+index+"','mzqAll"+index+"') class='Wdate' id='mzq_s"+index+"' value='' onClick='WdatePicker()'/></td><td><input type='text' name='mzq_e"+index+"' onblur=calTotal('mzq_s"+index+"','mzq_e"+index+"','mzqAll"+index+"') class='Wdate' id='mzq_e"+index+"' value='' onClick='WdatePicker()'/></td><td><input type='text' name='mzqAll"+index+"' size='10' id='mzqAll"+index+"' /> </td></tr>";
	$("#dynMzq").append(trStr);
}

function clearMzq(){
	var index=1;
	$("#dynMzq").find("tr").each(function(){
		if(index!=1){
			$(this).remove();
		}
		index=index+1;
	})
	
}
/****************************选择公司/项目 End*****************************/


/* idTabs ~ Sean Catchpole - Version 2.2 - MIT/GPL */
(function(){var dep={"jQuery":"jquery-1.11.1.min.js"};var init=function(){(function($){$.fn.idTabs=function(){var s={};for(var i=0;i<arguments.length;++i){var a=arguments[i];switch(a.constructor){case Object:$.extend(s,a);break;case Boolean:s.change=a;break;case Number:s.start=a;break;case Function:s.click=a;break;case String:if(a.charAt(0)=='.')s.selected=a;else if(a.charAt(0)=='!')s.event=a;else s.start=a;break;}}
if(typeof s['return']=="function")
s.change=s['return'];return this.each(function(){$.idTabs(this,s);});}
$.idTabs=function(tabs,options){var meta=($.metadata)?$(tabs).metadata():{};var s=$.extend({},$.idTabs.settings,meta,options);if(s.selected.charAt(0)=='.')s.selected=s.selected.substr(1);if(s.event.charAt(0)=='!')s.event=s.event.substr(1);if(s.start==null)s.start=-1;var showId=function(){if($(this).is('.'+s.selected))
return s.change;var id="#"+this.href.split('#')[1];var aList=[];var idList=[];$("a",tabs).each(function(){if(this.href.match(/#/)){aList.push(this);idList.push("#"+this.href.split('#')[1]);}});if(s.click&&!s.click.apply(this,[id,idList,tabs,s]))return s.change;for(i in aList)$(aList[i]).removeClass(s.selected);for(i in idList)$(idList[i]).hide();$(this).addClass(s.selected);$(id).show();return s.change;}
var list=$("a[href*='#']",tabs).unbind(s.event,showId).bind(s.event,showId);list.each(function(){$("#"+this.href.split('#')[1]).hide();});var test=false;if((test=list.filter('.'+s.selected)).length);else if(typeof s.start=="number"&&(test=list.eq(s.start)).length);else if(typeof s.start=="string"&&(test=list.filter("[href*='#"+s.start+"']")).length);if(test){test.removeClass(s.selected);test.trigger(s.event);}
return s;}
$.idTabs.settings={start:0,change:false,click:null,selected:".selected",event:"!click"};$.idTabs.version="2.2";$(function(){$(".idTabs").idTabs();});})(jQuery);}
var check=function(o,s){s=s.split('.');while(o&&s.length)o=o[s.shift()];return o;}
var head=document.getElementsByTagName("head")[0];var add=function(url){var s=document.createElement("script");s.type="text/javascript";s.src=url;head.appendChild(s);}
var s=document.getElementsByTagName('script');var src=s[s.length-1].src;var ok=true;for(d in dep){if(check(this,d))continue;ok=false;add(dep[d]);}if(ok)return init();add(src);})();
/* idTabs ~End*/

/*js　时间函数重构 */


//---------------------------------------------------  
// 判断闰年  
//---------------------------------------------------  
Date.prototype.isLeapYear = function()   
{   
    return (0==this.getYear()%4&&((this.getYear()%100!=0)||(this.getYear()%400==0)));   
}   


//+---------------------------------------------------  
//| 字符串转成日期类型   
//| 格式 MM/dd/YYYY MM-dd-YYYY YYYY/MM/dd YYYY-MM-dd  
//+---------------------------------------------------  
function StringToDate(DateStr)  
{   
  
    var converted = Date.parse(DateStr);  
    var myDate = new Date(converted);  
    if (isNaN(myDate))  
    {   
        //var delimCahar = DateStr.indexOf('/')!=-1?'/':'-';  
        var arys= DateStr.split('-');  
        myDate = new Date(arys[0],--arys[1],arys[2]);  
    }  
    return myDate;  
}  

//+---------------------------------------------------  
//| 取得当前日期所在月的最大天数  
//+---------------------------------------------------  
Date.prototype.MaxDayOfDate = function()  
{   
    var myDate = this;  
    var ary = myDate.toArray();  
    var date1 = (new Date(ary[0],ary[1]+1,1));  
    var date2 = date1.dateAdd(1,'m',1);  
    var result = dateDiff(date1.Format('yyyy-MM-dd'),date2.Format('yyyy-MM-dd'));  
    return result;  
}  
  
//+---------------------------------------------------  
//| 日期时间检查  
//| 格式为：YYYY-MM-DD HH:MM:SS  
//+---------------------------------------------------  
function CheckDateTime(str)  
{   
    var reg = /^(\d+)-(\d{ 1,2 })-(\d{ 1,2 }) (\d{ 1,2 }):(\d{ 1,2 }):(\d{ 1,2 })$/;   
    var r = str.match(reg);   
    if(r==null)return false;   
    r[2]=r[2]-1;   
    var d= new Date(r[1],r[2],r[3],r[4],r[5],r[6]);   
    if(d.getFullYear()!=r[1])return false;   
    if(d.getMonth()!=r[2])return false;   
    if(d.getDate()!=r[3])return false;   
    if(d.getHours()!=r[4])return false;   
    if(d.getMinutes()!=r[5])return false;   
    if(d.getSeconds()!=r[6])return false;   
    return true;   
}  
//+---------------------------------------------------  
//| 比较日期差 dtEnd 格式为日期型或者 有效日期格式字符串  
//+---------------------------------------------------  
Date.prototype.DateDiff = function(strInterval, dtEnd) {   
    var dtStart = this;  
    if (typeof dtEnd == 'string' )//如果是字符串转换为日期型  
    {   
        dtEnd = StringToDate(dtEnd);  
    }  
    switch (strInterval) {   
        case 's' :return parseInt((dtEnd - dtStart) / 1000);  
        case 'n' :return parseInt((dtEnd - dtStart) / 60000);  
        case 'h' :return parseInt((dtEnd - dtStart) / 3600000);  
        case 'd' :return parseInt((dtEnd - dtStart) / 86400000);  
        case 'w' :return parseInt((dtEnd - dtStart) / (86400000 * 7));  
        case 'm' :return (dtEnd.getMonth()+1)+((dtEnd.getFullYear()-dtStart.getFullYear())*12) - (dtStart.getMonth()+1);  
        case 'y' :return dtEnd.getFullYear() - dtStart.getFullYear();  
    }  
}  
//+---------------------------------------------------  
//| 求两个时间的天数差 日期格式为 YYYY-MM-dd   
//+---------------------------------------------------  
function daysBetween(DateOne,DateTwo)  
{   
    var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-'));  
    var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1);  
    var OneYear = DateOne.substring(0,DateOne.indexOf ('-'));  
  
    var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-'));  
    var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1);  
    var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-'));  
  
    var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);   
    return Math.abs(cha);  
}  
  
  
//+---------------------------------------------------  
//| 日期计算  
//+---------------------------------------------------  
Date.prototype.DateAdd = function(strInterval, Number) {   
    var dtTmp = this;  
    switch (strInterval) {   
        case 's' :return new Date(Date.parse(dtTmp) + (1000 * Number));  
        case 'n' :return new Date(Date.parse(dtTmp) + (60000 * Number));  
        case 'h' :return new Date(Date.parse(dtTmp) + (3600000 * Number));  
        case 'd' :return new Date(Date.parse(dtTmp) + (86400000 * Number));  
        case 'w' :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));  
        case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());  
        case 'm' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());  
        case 'y' :return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());  
    }  
}  

//---------------------------------------------------  
// 日期格式化  
// 格式 YYYY/yyyy/YY/yy 表示年份  
// MM/M 月份  
// W/w 星期  
// dd/DD/d/D 日期  
// hh/HH/h/H 时间  
// mm/m 分钟  
// ss/SS/s/S 秒  
//---------------------------------------------------  
Date.prototype.Format = function(formatStr)   
{   
    var str = formatStr;   
    var Week = ['日','一','二','三','四','五','六'];  
  
    str=str.replace(/yyyy|YYYY/,this.getFullYear());   
    str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));   
  
    str=str.replace(/MM/,this.getMonth()>=9?(this.getMonth()+1).toString():'0' + (this.getMonth()+1));   
    str=str.replace(/M/g,this.getMonth()+1);   
  
    str=str.replace(/w|W/g,Week[this.getDay()]);   
  
    str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());   
    str=str.replace(/d|D/g,this.getDate());   
  
    str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());   
    str=str.replace(/h|H/g,this.getHours());   
    str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());   
    str=str.replace(/m/g,this.getMinutes());   
  
    str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());   
    str=str.replace(/s|S/g,this.getSeconds());   
  
    return str;   
} 

//+---------------------------------------------------  
//| 取得日期数据信息  
//| 参数 interval 表示数据类型  
//| y 年 m月 d日 w星期 ww周 h时 n分 s秒  
//+---------------------------------------------------  
Date.prototype.DatePart = function(interval)  
{   
    var myDate = this;  
    var partStr='';  
    var Week = ['日','一','二','三','四','五','六'];  
    switch (interval)  
    {   
        case 'y' :partStr = myDate.getFullYear();break;  
        case 'm' :partStr = myDate.getMonth()+1;break;  
        case 'd' :partStr = myDate.getDate();break;  
        case 'w' :partStr = Week[myDate.getDay()];break;  
        case 'ww' :partStr = myDate.WeekNumOfYear();break;  
        case 'h' :partStr = myDate.getHours();break;  
        case 'n' :partStr = myDate.getMinutes();break;  
        case 's' :partStr = myDate.getSeconds();break;  
    }  
    return partStr;  
}  
//时间戳转换成具体时间
function getLocalTime(nS) {
		var date=new Date(parseInt(nS));
	    return date.Format("yyyy-MM-dd HH:mm:ss");     
}  
/*js　时间函数重构 End*/


/*
 *人员选择相关函数
  @param selList  选择人员的json字符串{"userid":"userid1","userName":"userName1"},{"userid":"userid2","userName":"userName2"}
*/
function initPage(){
	if(selList!=""){
		createSelFieldList();
	}
}
//添加单个选择的数据
function addSelectSingle(){
	var selJson;//已选择数据
	var curJson;//当前已选择数据
	var addJson;//需要追加的json;
	if(selList!=""){
		selJson=eval('([' + selList + '])');
		curJson=eval('(['+getStrFromGrid()+'])');
		addJson=getNotExsit(selJson,curJson);
		if(addJson!=""){
			selList=selList+","+addJson;
		}
	}else{
		selList=getStrFromGrid();
	}
	createSelFieldList();

}
//添加当前grid中所有的数据
function addGridAll(){
	selectAll();
	addSelectSingle();
}
//从选择的列表中移除指定的数据
function removeSingle(){
	 selList=getStrFromSel();
   	createSelFieldList();
}
//移除选择列表中的所有数据
function removeAll(){
	$("#selList").html("");
	selList="";
}
//获取selList中不包含的数据
function getNotExsit(selJson,curJson){
	var resultList="";
	var flag=true;
	for(var i=0;i<curJson.length;i++){
		flag=true;
		for(var j=0;j<selJson.length;j++){
			if(curJson[i][field]==selJson[j][field]){
				//如果相等，则说明存在
				flag=false;
			}
		}
		//如果flag为true，则说明不存在此用户，可以添加到选择列表中
		if(flag){
			resultList=resultList+",{\""+field+"\":\""+curJson[i][field]+"\",\""+fieldName+"\":\""+curJson[i][fieldName]+"\"}";
		}
	}
	if(resultList!=""){
		resultList=resultList.substring(1,resultList.length);
	}
	return resultList;
}
/**
 * 通用选人函数
 * @param uid
 * @param field
 * @param fieldName
 * @return
 */
function SelUser(uid,field,fieldName){
	var userids=$("#"+uid).val();
	var url="uc_manage/selUser/"+userids+"_"+field+"_"+fieldName+"___";
	openTitleLayer("选择用户",url,975,450);
}

//从grid中获取选中的值,并将数据拼接成json数组字符串
function getStrFromGrid(){
	var resultStr="";
	var fieldArr,fieldNameArr;
	var checkList;
	var checkV="";
	var fieldList="";
	var fieldNameList="";
	if(field!="" && fieldName!=""){
		checkList=$('#searchTable').datagrid('getSelections');
		for(var i=0;i<checkList.length;i++){
			fieldList=fieldList+","+checkList[i].userId;
			fieldNameList=fieldNameList+","+checkList[i].UserName;
		}
		
		if(fieldList.indexOf(",")>-1){
			fieldList=fieldList.substring(1,fieldList.length);
			fieldNameList=fieldNameList.substring(1,fieldNameList.length);
		}
		if(fieldList!="" && fieldNameList!=""){
			if(fieldList.indexOf(",")>-1){
				fieldArr=fieldList.split(",");
				fieldNameArr=fieldNameList.split(",");
				for(var i=0;i<fieldArr.length;i++){
					resultStr=resultStr+",{\""+field+"\":\""+fieldArr[i]+"\",\""+fieldName+"\":\""+fieldNameArr[i]+"\"}";
				}
				resultStr=resultStr.substring(1,resultStr.length);
			}else{
				resultStr=resultStr+"{\""+field+"\":\""+fieldList+"\",\""+fieldName+"\":\""+fieldNameList+"\"}";
			}
		}
	}
	return resultStr;
}
//根据selList在页面打印出以选择的属性和属性值
function createSelFieldList(){
	var selJson=eval('([' + selList + '])');
	var html="";
	for(var i=0;i<selJson.length;i++){
		html=html+"<li class=\"list-group-item\"><input type=\"checkbox\" name=\"fieldList\" value=\""+selJson[i][field]+"\" /><span id=\""+selJson[i][field]+"\">"+selJson[i][fieldName]+"</span></li>";	
	}
	$("#selList").html(html);
}
//从已选择的列表中获取没有被选中的
function getStrFromSel(){
	var resultStr="";
	$("#selList").find('input:checkbox').each(function(){
		if(!$(this).is(':checked')){
			resultStr=resultStr+",{\""+field+"\":\""+$(this).val()+"\",\""+fieldName+"\":\""+$("#"+$(this).val()).html()+"\"}";
		}
	});
	if(resultStr!=""){
		resultStr=resultStr.substring(1,resultStr.length);		
	}
	return resultStr;
}
//选中所有
function selectAll(){
	$(".bsgrid_editgrid_check").attr("checked",true);
	var inputTag=document.getElementsByTagName("input");
	for(var i=0;i<inputTag.length;i++){
		if(inputTag[i].className=="bsgrid_editgrid_check"){
			inputTag[i].checked=true;
		}
	}
}
//给父窗体赋值
function initParentWindowVal(workflow){
	var fieldList="";
	var fieldNameList="";
	$("#selList").find('input:checkbox').each(function(){
			fieldList=fieldList+","+$(this).val();
			fieldNameList=fieldNameList+","+$("#"+$(this).val()).html();
	});
	if(fieldList!="" && fieldNameList!=""){
		fieldList=fieldList.substring(1,fieldList.length);
		fieldNameList=fieldNameList.substring(1,fieldNameList.length);
	}
	if(workflow==1){
		//工作流节点选择人，需要给节点名称赋值
		if(fieldList.indexOf(",")==-1){
			if(fieldList!=""){
				//查询选中用户部门
				var deptName = "";
				var url="/leasePro/uc_manage/getDeptName/"+fieldList;
				jQuery.ajax({
			        type: "post",
			        async: false,          
			        url: url,
			        contentType: "application/json; charset=utf-8",
			        dataType: "json",
			        cache: false,
			        success: function (data) {
			            deptName = data.deptName;
			        },
			        error: function (err) {}
			    });
				window.parent.$("#"+nodeName).val(deptName);
			}else{
				window.parent.$("#"+nodeName).val("");
			}
		}else{
			window.parent.$("#"+nodeName).val("联合审批");
		}
		
	}
	window.parent.$("#"+field).val(fieldList);
	window.parent.$("#"+fieldName).val(fieldNameList);
	if(window.parent.saveNodeInfo){
		var nodeId=$("#nodeId").val();
		var groupId=$("#groupId").val();
		var index=field.substring(4,field.length);
		window.parent.saveNodeInfo(nodeId,index,groupId);
	}
}

/**
 * 确认选择
 * @param workflow:(参数可选)1为工作流节点表单
 * @return
 */
function selOk(workflow){
	addSelectSingle();
	initParentWindowVal(workflow);
	closeLayer();
}

//表格全选or全不选
function checkAllOrNot(){
		var val=document.getElementById("thCheck").checked;
		var checkList=document.getElementsByName("tdCheck");
		for(var i=0;i<checkList.length;i++){
			checkList[i].checked=val;
		}
}
//单个checkbox单击事件
function selectOne(){
	var selCount=0;
	var total=0;
	var checkList=document.getElementsByName("tdCheck");
	total=checkList.length;
	for(var i=0;i<checkList.length;i++){
		if(checkList[i].checked){
			selCount++;
		}
	}
	if(selCount!=total){
		document.getElementById("thCheck").checked=false;
	}else{
		document.getElementById("thCheck").checked=true;
	}
}


/**
 *	type 1: 身份证    2：电话号码
 *	号码放大镜随着字数延伸
 *	身份证分割： 3 3 4 4 4   手机号码分割： 3 4 4
 */
$.fn.bigGlass = function(type){
	var glassT = $(this).offset().top, glassL = $(this).offset().left;//定义预展示输入框的坐标
	var gId = $(this).attr("id");
	var glassStr = '<div id="bigGlass"><nobr><span></span><span></span><span></span><span></span></nobr></div>';
	$(this).after($(glassStr));
	$(this).keyup(function(){
		showBigGlass();
	})
	//生成放大镜
	function showBigGlass(){
		var inputVal = $("#"+gId).val(), l = inputVal.length;
		$("#bigGlass").css({"top":(glassT-50)+"px","left":glassL+"px"});
		 style="top:'+(glassT-50)+'px;left:'+glassL+'px;"
		if(!inputVal){
			$("#bigGlass").hide();
			return false;
		}
		//身份证号码与电话号码展示逻辑不同，做区分
		$("#bigGlass").html('<nobr><span></span><span></span><span></span><span></span></nobr>');
		if(type == 1){
			if(l <= 3){
				$("#bigGlass").find("span").eq(0).text(inputVal);
			}else if(l <= 6){
				$("#bigGlass").find("span").eq(0).text(inputVal.substring(0,3));
				$("#bigGlass").find("span").eq(1).text(inputVal.substring(3,l));
			}else if(l <= 14){
				$("#bigGlass").find("span").eq(0).text(inputVal.substring(0,3));
				$("#bigGlass").find("span").eq(1).text(inputVal.substring(3,6));
				$("#bigGlass").find("span").eq(2).text(inputVal.substring(6,l));
			}else{
				$("#bigGlass").find("span").eq(0).text(inputVal.substring(0,3));
				$("#bigGlass").find("span").eq(1).text(inputVal.substring(3,6));
				$("#bigGlass").find("span").eq(2).text(inputVal.substring(6,14));
				$("#bigGlass").find("span").eq(3).text(inputVal.substring(14,l));
			}
		}else{
			if(l <= 3){
				$("#bigGlass").find("span").eq(0).text(inputVal);
			}else if(l <= 7){
				$("#bigGlass").find("span").eq(0).text(inputVal.substring(0,3));
				$("#bigGlass").find("span").eq(1).text(inputVal.substring(3,l));
			}else{
				$("#bigGlass").find("span").eq(0).text(inputVal.substring(0,3));
				$("#bigGlass").find("span").eq(1).text(inputVal.substring(3,7));
				$("#bigGlass").find("span").eq(2).text(inputVal.substring(7,l));
			}
		}
		$("#bigGlass").show();
	}
	//控制数字放大镜的显示与销毁
	$(document).click(function(event){
		var obj = event.srcElement || event.target;
		if($(obj).attr("id") != gId){
			$("#bigGlass").html("").hide();
		}else{
			showBigGlass();
		}
	});
}

//打印js
function printPage(id){
	var content=$("#"+id).html();
	$("body").html(content);
	window.print(); 
}

/**
 * 弹窗处理工作流程表单
 * @param DocURL
 * @param lnum
 * @param rnum
 * @return
 */
function OpenUrl(DocURL,lnum,rnum)
{
 var swidth=screen.availWidth;
 var sheight=screen.availHeight;
 if(!lnum) lnum=24;
 if(!rnum) rnum=80;
 var wwidth=swidth-lnum;
 var wheight=sheight-rnum;
 var wleft=(swidth/2-0)-wwidth/2-5;
 var wtop=(sheight/2-0)-wheight/2-25;
 return window.open(DocURL,'','Width='+wwidth+'px,Height='+wheight+'px,Left='+wleft+',Top='+wtop+',location=no,menubar=no,status=yes,resizable=yes,scrollbars=yes,resezie=no');
}

//----------------------------------退出系统--------------------------------
function layout(){
	layer.confirm("您确定要退出吗", {icon: 3}, function(index){
		var url="layout"
			var pathName = window.document.location.pathname;
			var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
			window.location.href=projectName+"/"+url;
	});
}
//-----------------------------workflow相关 -------------------------------------
function getcurUserByNode(docUnid){
	var curUsers="";
	var hostName=$("base").attr("href");
	var url=hostName+"uc_workflow/getCurUser";
	jQuery.ajax({
        type:"post",
        async:false,
        url:url,
        data:{docUnid:docUnid},
        success:function(data){
            curUsers=data;
        }
	})
	return curUsers;
}



//打印功能
function startPrint(obj)
{
  var oWin=window.open("","_blank");

  var strPrint="<style type=\"text/css\">#content{ width:1000px; font-size:12px}</style>\n";
  strPrint=strPrint + "<link rel='stylesheet' href='/leasePro/css/vivo.css'> \n";
  strPrint=strPrint + "<link rel='stylesheet' href='/leasePro/css/bootstrap.css'> \n";
  strPrint=strPrint + "<script type=\"text/javascript\">\n";

  strPrint=strPrint + "function printWin()\n";

  strPrint=strPrint + "{";

  strPrint=strPrint + "var oWin=window.open(\"\",\"_blank\");\n";

  strPrint=strPrint + "oWin.document.write(document.getElementById(\"content\").innerHTML);\n";

  strPrint=strPrint + "oWin.focus();\n";

  strPrint=strPrint + "oWin.document.close();\n";

  strPrint=strPrint + "oWin.print()\n";

  strPrint=strPrint + "oWin.close()\n";

  strPrint=strPrint + "}\n";

  strPrint=strPrint + "<\/script>\n";

  strPrint=strPrint + "<br><br><div style='text-align:right;margin-right:200px'><button onclick='this.style.display=\"none\";window.print()' style='padding:10px;'>点此打印</button></div>\n";
  
  strPrint=strPrint + "<div id=\"content\" style='MARGIN-RIGHT: auto; MARGIN-LEFT: auto;TEXT-ALIGN: center;padding-top:20px'><p align='center' style='font-size:24px;font-weight:blod'>《合同审批表》</p><br>\n";

  strPrint=strPrint + obj.innerHTML + "\n";

  strPrint=strPrint + "</div>\n";

  strPrint=strPrint + "<br>\n";

  //strPrint=strPrint + "<div style='text-align:center'><button onclick='this.style.display=\"none\";window.print()' style='padding-left:4px;padding-right:4px;'>打  印</button></div>\n";
  oWin.document.write(strPrint);

  oWin.focus();

  oWin.document.close();

}
//把报表数据转化成列表所需的json格式
function dataToJson(dynamic_columns,dynamic_columnscn,dynamic_column_align,html){
	var jsonData="{\"success\":true,\"totalRows\":";
	var dataList=html.split("#");
	if(dataList.length>=0){
		jsonData=jsonData+dataList.length;
	}else{
		jsonData=jsonData+"0";
	}
	jsonData=jsonData+",\"curPage\":1,\"data\":[";
	var tempData="";
	//格式化data
	for(var i=0;i<dataList.length;i++){
		if(i==0){
			tempData="{";			
		}else{
			tempData=tempData+","+"{";
		}
		var colVArr=dataList[i].split(",");
		var tmpData="";
		for(var j=0;j<dynamic_columns.length;j++){
			if(j==0){
				tmpData=tmpData+"\""+dynamic_columns[j]+"\":\""+colVArr[j]+"\"";
			}else{				
				tmpData=tmpData+","+"\""+dynamic_columns[j]+"\":\""+colVArr[j]+"\"";
			}
		}
		tempData=tempData+tmpData+"}";
	}
	jsonData=jsonData+tempData+"],\"userdata\":{\"dynamic_columns\":[";
	//格式化dynamic_columns,dynamic_columnscn,dynamic_foot,dynamic_column_align
	var columnsData="";
	var columnscnData="";
	var dynamic_footData="";
	var dynamic_column_alignData="";
	for(var i=0;i<dynamic_columns.length;i++){
		if(i==0){
			columnsData="\""+dynamic_columns[i]+"\"";
			columnscnData="\""+dynamic_columnscn[i]+"\"";
			dynamic_column_alignData="\""+dynamic_column_align[i]+"\"";
		}else{
			columnsData=columnsData+","+"\""+dynamic_columns[i]+"\"";
			columnscnData=columnscnData+","+"\""+dynamic_columnscn[i]+"\"";
			dynamic_column_alignData=dynamic_column_alignData+","+"\""+dynamic_column_align[i]+"\"";
		}
	}
	jsonData=jsonData+columnsData+"],\"dynamic_columnscn\":["+columnscnData+"],\"dynamic_foot\":[],\"dynamic_column_align\":["+dynamic_column_alignData+"]}";
	return jsonData+"}";
}

//列表关键字搜索，回车搜索操作
function enterSearch(src,e){
 	if(window.event){
    	keyPressed = window.event.keyCode; // IE
 	}else{
     	keyPressed = e.which; // Firefox
		}
 	if(keyPressed==13){ 
     	search();
	}
}
function enterSearchOne(src,e){
 	if(window.event){
    	keyPressed = window.event.keyCode; // IE
 	}else{
     	keyPressed = e.which; // Firefox
		}
 	if(keyPressed==13){ 
     	searchOne();
	}
}

//固定表头 
function fixedHeader(iFirst) { 
	var currentDocumentHeight = $(document).height();
	
    if (fixedGridLock) {
        return;
    }
    fixedGridLock = true;
    if ($.trim(iFirst) != 'first') {
        $('#searchTable thead tr:eq(0)').remove();
    }
    if (fixedGridHeight < $('#searchTable').height()) {
        $('#searchTable_fixedDiv').height(fixedGridHeight);
        $('#searchTable').width($('#searchTable_fixedDiv').width() - 18);
    } else {
        $('#searchTable_fixedDiv').height($('#searchTable').height());
        $('#searchTable').width($('#searchTable_fixedDiv').width() - 1);
    }
    $('#searchTable thead tr:eq(0)').clone(true).prependTo('#searchTable thead');
    $('#searchTable thead tr:eq(0)').css({'z-index': 10, position: 'fixed'}).width($('#searchTable thead tr:last').width());

    var thObjs = $('#searchTable thead tr:eq(1) th');
    thObjs.each(function (i) {
        var thObj = $(this);
        $('#searchTable thead tr:eq(0) th:eq(' + i + ')').height(thObj.height() + 1).width(thObj.width() + 1);
    });
    fixedGridLock = false;
}